using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace ZSW.Framework.EditorTools
{
    /// <summary>
    /// 重新设置父物体
    /// </summary>
    public class ResetSiblingIndex
    {
        [MenuItem("Tools/Transform/Reset Sibling Index 2 Top")]
        [MenuItem("GameObject/Tools/Reset Sibling Index 2 Top")]
        public static void SetTop()
        {
            // 获取当前选中的对象
            GameObject obj = Selection.activeGameObject;
            if (obj != null)
            {
                // 记录当前操作，以便进行Undo
                Undo.RecordObject(obj.transform, "Set index to top");

                // 获取对象的父对象
                Transform parent = obj.transform.parent;
                if (parent != null)
                {
                    // 使当前选中的对象位于父对象子列表的最前面
                    int index = 0;
                    obj.transform.SetSiblingIndex(index);
                }
            }
            else
            {
                Debug.Log("No game object is selected.");
            }
        }

        [MenuItem("Tools/Transform/Reset Sibling Index 2 Down")]
        [MenuItem("GameObject/Tools/Reset Sibling Index 2 Down")]
        public static void SetDown()
        {
            // 获取当前选中的对象
            GameObject obj = Selection.activeGameObject;
            if (obj != null)
            {
                // 记录当前操作，以便进行Undo
                Undo.RecordObject(obj.transform, "Set index to top");

                // 获取对象的父对象
                Transform parent = obj.transform.parent;
                if (parent != null)
                {
                    // 使当前选中的对象位于父对象子列表的最前面
                    int index = parent.childCount - 1;
                    obj.transform.SetSiblingIndex(index);
                }
            }
            else
            {
                Debug.Log("No game object is selected.");
            }
        }

    }
}

